package com.allwees.bs.module.fms.req.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.core.modelbase.branch.EBranchType;
import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.bs.module.fms.entity.MerchantAccount;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 商户账户QueryReq
 *
 * @author yangylsky
 * @since 2020-01-03
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class MerchantAccountQueryReq extends QueryReq<MerchantAccount> {
	private EBranchType branchType;

	private String branchUuid;

	private  Integer accountType;

	/**
	 * 注册时间
	 */
	private Date createdAtFrom;
	/**
	 * 注册时间
	 */
	private Date createdAtTo;

	@Override
	protected void buildQuery(QueryWrapper<MerchantAccount> queryWrapper) {
		queryWrapper
			.eq(StringUtils.isNotBlank(branchUuid), "branch_uuid", branchUuid)
				.ge(createdAtFrom != null, "created_at", createdAtFrom)
				.le(createdAtTo != null, "created_at", createdAtTo)
				.eq(accountType != null, "account_type", accountType)
			.and(StringUtils.isNotBlank(q), wrapper -> {
					wrapper.eq("uuid", q)
						.or().eq("account_no", q)
						.or().eq("mobile", q);
				})
			.eq(null != branchType, "branch_type", branchType);
	}
}
